<?php
/**
 * Created by 项目.
 * User: xuguopeng
 * Date: 2020-06-12
 * Time: 15:41
 * 用户不良记录表
 */

namespace app\api\controller\v1;

use app\api\model\UserBadRecords;
use think\facade\Request;

class Records
{
    /**
     * 获取列表
     * @validate('PagingParameter')
     * @auth('用户不良记录列表','用户不良记录管理')
     */
    public function getDataList($page,$limit,$name,$lin_user_id)
    {
        $where = [];
        if($name) {
            $where[] = ['name','like','%'.$name.'%'];
        }
        if($lin_user_id > 1) {
            $where[] = ['lin_user_id','eq',$lin_user_id];
        }
        $query = UserBadRecords::where($where)->with('adminUser')
            ->order('user_bad_records.id desc');
        $count = $query->count();
        $result = $query->page($page, $limit)->select()->toArray();
        $data['count'] = $count;
        $data['data'] = $result;
        return $data;
    }

    /**
     * 添加
     * @validate('CheckRecords')
     */
    public function createData()
    {
        $data = Request::post();
        UserBadRecords::create($data);
        return writeJson(201, [], '添加成功！');
    }
}